package zhaoyong.wang.tlias.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import zhaoyong.wang.tlias.mapper.EmpMapper;
import zhaoyong.wang.tlias.pojo.Emp;
import zhaoyong.wang.tlias.pojo.PageBean;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServicelmpl  implements EmpService{
    @Autowired
  private  EmpMapper empMapper;


    @Override
    public PageBean page(Integer page, Integer pageSize,String name,Short gender,LocalDate begin,LocalDate end) {
        PageBean pageBean = new PageBean();
        Long toal =empMapper.total();
        int start = (page - 1)*pageSize;
       List<Emp> list = empMapper.pagebean(start,pageSize,name,gender,begin,end);
        pageBean.setRows(list);
        pageBean.setTotal(toal);
        pageBean.setName(name);
        pageBean.setGender(gender);
        pageBean.setBegin(begin);
        pageBean.setEnd(end);
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void insert(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        emp.setCreateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getByid(Integer id) {
        return empMapper.getByid(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getByusernameandpassword(emp);
    }


}
